package fr.mairie.parc.control.user;

import java.util.ArrayList;
import java.util.List;

import org.apache.click.Page;
import org.apache.click.control.AbstractContainer;
import org.apache.click.control.AbstractLink;
import org.apache.click.control.Checkbox;
import org.apache.click.control.Column;
import org.apache.click.control.PageLink;
import org.apache.click.control.Table;
import org.apache.click.control.TextField;
import org.apache.click.dataprovider.DataProvider;
import org.apache.click.extras.control.FieldColumn;
import org.apache.click.extras.control.TableInlinePaginator;
import org.apache.click.util.Bindable;

import fr.mairie.parc.domain.User;

public class UserCheckBoxTable extends AbstractContainer {
	
	private static final long serialVersionUID = 1L;
	private Object owner;

	@Bindable protected Table table = new Table("table");
	@Bindable protected PageLink actionRowLink;
	private Column actionColumn;
	private List<AbstractLink> actionColumnLinks = new ArrayList<AbstractLink>();

	public UserCheckBoxTable (String name, Object owner,
			Class<? extends Page> actionRowPageClass) {
		super(name);
		this.owner = owner;

		table.setClass(Table.CLASS_ITS);
		table.setPageSize(5);
		table.setShowBanner(true);
		table.setSortable(true);
		table.setPaginator(new TableInlinePaginator(table));
		table.setPaginatorAttachment(Table.PAGINATOR_INLINE);

		FieldColumn column = new FieldColumn("name", new TextField());
		table.addColumn(new Column("idUser", "ID"));
		table.addColumn(new Column("idMateriel", "IDMateriel"));
		table.addColumn(new Column("nom", "Nom"));
		table.addColumn(new Column("prenom", "Prenom"));
		table.addColumn(new Column("direction", "Direction"));
		table.addColumn(new Column("service", "Service"));
		table.addColumn(new Column("batiment", "Batiment"));
		table.addColumn(new Column("etage", "Etage"));
		table.addColumn(new Column("bureau", "Bureau"));
		
		
		column = new FieldColumn("choisir", new Checkbox());
		column.setAttribute("idMateriel", getId());
        column.setTextAlign("center");
        table.addColumn(column);
        add(table);

		/*{
			PageLink viewRowLink = new PageLink("id", ViewUserPage.class);
			viewRowLink.setImageSrc("/assets/images/16x16/application_form_magnify.png");
			actionColumnLinks.add(viewRowLink);
		}

		if (actionRowPageClass != null && actionRowPageClass != ViewUserPage.class) {
			actionRowLink = new PageLink(actionRowPageClass);
			actionRowLink.setImageSrc("/assets/images/16x16/application_form_edit.png");
			actionColumnLinks.add(actionRowLink);
		}
		AbstractLink[] linksArray = actionColumnLinks.toArray(new AbstractLink[actionColumnLinks.size()]);
		actionColumn.setDecorator(new LinkDecorator(table, linksArray, "idUser"));

		actionColumn.setSortable(false);
		table.addColumn(actionColumn);*/

		
	}

	public Object getOwner() {
		return owner;
	}

	/*public void addActionColumnLink(AbstractLink link) {
		actionColumnLinks.add(link);
		updateActionColumnLinks();
	}

	protected void updateActionColumnLinks() {
		AbstractLink[] linksArray = actionColumnLinks.toArray(new AbstractLink[actionColumnLinks.size()]);
		actionColumn.setDecorator(new LinkDecorator(table, linksArray, "idUser"));
	}*/

	public void setDataProvider(DataProvider<User> dataProvider) {
		table.setDataProvider(dataProvider);
	}

	public void setRowList(List<User> m) {
		table.setRowList(m);
	}

	@SuppressWarnings("unchecked")
	public List<User> getRowList() {
		return (List<User>) table.getRowList();
	}

}
